home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / aecdev.aedaemon / aecdev.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.7 KB  |  116 lines

  1. /*
  2.     File:        AECdev.h
  3.  
  4.     Contains:    AECDEV demonstrates the techniques needed to send AppleEvents
  5.                 from a CDEV/DA/INIT/Driver.
  6.                 Requires the sample AEDaemon to work.
  7.     
  8.                 The techniques used in AECdev are the same you need to use to send AppleEvents
  9.                 from any non-application piece of code, DAs/INIT/Drivers, or anything else.
  10.                 Since the High Level Event manager will not let anyone post High Level Events 
  11.                 unless they have an event loop, your non-event looped code must rely
  12.                 on a 'buddy' (in this case AEDaemon) to do the sending for you.
  13.                 There's not really much more code to write (just some PPC code), it's
  14.                 mainly a matter of moving the code from the CDEV to the backgrounder.
  15.     
  16.                 Using a buddy and PPC can give you all the functionality of AppleEvents.
  17.  
  18.     Written by: C.K. Haun    
  19.  
  20.     Copyright:    Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved.
  21.  
  22.                 You may incorporate this Apple sample source code into your program(s) without
  23.                 restriction. This Apple sample source code has been provided "AS IS" and the
  24.                 responsibility for its operation is yours. You are not permitted to redistribute
  25.                 this Apple sample source code as "Apple sample source code" after having made
  26.                 changes. If you're going to re-distribute the source, we require that you make
  27.                 it clear in the source that the code was descended from Apple sample source
  28.                 code, but that you've made changes.
  29.  
  30.     Change History (most recent first):
  31.                 7/20/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  32.                 
  33.  
  34. */
  35. #include <Types.h>
  36. #include <Memory.h>
  37. #include <Quickdraw.h>
  38. #include <TextEdit.h>
  39. #include <Dialogs.h>
  40. #include <Devices.h>
  41. #include <Scrap.h>
  42. #include <menus.h> 
  43. #include <PPCToolbox.h>
  44. #include <AppleEvents.h>
  45. #include <StandardFile.h>
  46. #include <EPPC.h>
  47. #include <Aliases.h>
  48. #include <events.h>
  49. #include <gestaltequ.h>
  50. #include <ToolUtils.h>
  51.  
  52. /* Types */
  53. struct MyPPCRec {
  54. PPCParamBlockRec    pB;
  55. Ptr        buffer;        /* buffer we're using */
  56. Size bufferSize;    /* guess */
  57. Handle dataToXfer;
  58. PPCPortPtr myPort;
  59. PPCPortPtr buddyPortPtr;
  60. PPCPortRefNum ourPort;
  61. PPCSessRefNum currentSessionRef;
  62.  
  63. };
  64. typedef struct MyPPCRec MyPPCRec, *MyPPCRecPtr,**MyPPCRecHandle;
  65.  
  66.  
  67. typedef struct CDEVRec {
  68. Handle spare;
  69. MyPPCRecPtr myPPCBlock;
  70. /* LocationName won't be needed, since we're staying local */
  71. Boolean searchForTarget;  /* searchForTarget is our flag to tell us that we do not */
  72.                         /* know where AEBuddy is yet, and we have to keep looking. */
  73.                         /*  It also implies (if true) that PBCat has already been */
  74.                         /* called, if necessary */
  75. Boolean noBuddy;        /* PBCatSearch failed, give it up */
  76. Boolean notSys7;
  77. Boolean eventPending;
  78. } CDEVRec, *CDEVPtr, **CDEVHnd;
  79.  
  80.  
  81.  
  82.  
  83. struct MyPPCRecDeamon { /* to differenciact it from the one I'm using in teh CDEV */
  84. PPCParamBlockRec    pB;
  85. Ptr        buffer;        /* buffer we're using */
  86. Size bufferSize;    /* guess */
  87. Handle dataToXfer;
  88. PPCPortPtr myPort;
  89. PPCPortRefNum ourPort;
  90. PPCSessRefNum currentSessionRef;
  91.  
  92. };
  93. typedef struct MyPPCRecDeamon MyPPCRecDeamon, *MyPPCRecPtrDeamon,**MyPPCRecHandleDeamon;
  94. #define kOneK 1024
  95. #define kMyTypeOfData 'MAVT'
  96. #define kGenericCreator '????'
  97. #define kSendButton 1
  98. #define kNoBuddyAlert -4048
  99. #define kNot70 -4049
  100. #define kStringsID -4048
  101. #define kBrowse1 1
  102. #define kBrowse2 2
  103. #define kMyName 3
  104. #define kWatchCursor 4
  105.  
  106.  pascal Handle AECDEV(short message, short item, short numItems, short CPanelID, EventRecord *theEvent, Handle cdevStorage,
  107.                      DialogPtr CPDialog);
  108.  ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem);
  109.  void FindATarget(CDEVHnd storage);
  110.  void FindAEBuddy(CDEVHnd storage);
  111.  void FireTheEvent(Handle packedEvent, CDEVHnd storage);
  112.  void OpenComplete(PPCStartPBPtr p);
  113.  void StartComplete(PPCWritePBPtr p);
  114.  void WriteComplete(PPCEndPBPtr p);
  115.  void EndComplete(PPCClosePBPtr p);
  116.